package model

import (
	"fmt"
	"github.com/jinzhu/gorm"
	_ "github.com/jinzhu/gorm/dialects/mysql"
	"learngin/config"
)

var DB *gorm.DB
var err error

func init() {
	cfg, err1 := config.ParseConfig("./config/app.json")
	if err1 != nil {
		fmt.Println("--config 配置文件读取失败--", err)
		return
	}
	fmt.Println()
	dsn := cfg.Database.User + ":" + cfg.Database.Password + "@tcp(" + cfg.Database.Host + ":" + cfg.Database.Port + ")/" + cfg.Database.DbName + "?charset=utf8"
	dbType := "mysql"
	DB, err = gorm.Open(dbType, dsn)
	if err != nil {
		fmt.Println("--数据库链接失败--", err)
		return
	}
	//DB.LogMode(true)
}
